﻿using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Markup;
using YArchitech.LIB;
using YJKMenuAssist.DataManagement;
using YJKMenuAssist.MenuManageControls;

namespace YJKMenuAssist.Controls
{
	public partial class AutoDefMenuTab : UserControl, IComponentConnector
	{
		public AutoDefMenuTab()
		{
			this.InitializeComponent();
			this.rightList.LeftList = this.leftList;
			this.rightList.CenterList = this.centerList;
		}

		public void IniData(CommandTableInfos commandTableInfos)
		{
			this.m_CommandTableInfos = commandTableInfos;
			this.leftList.IniTreeData(commandTableInfos);
			this.rightList.CommandTableInfos = commandTableInfos;
			this.rightList.IniTreeData(Path.Combine(Product.UserDataLocation, "CustomMenu.xml"));
			this.leftList.tvProperties.SelectedItemChanged += this.tvProperties_SelectedItemChanged;
		}

		private void tvProperties_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
		{
			PropertyNodeItem propertyNodeItem = this.leftList.tvProperties.SelectedItem as PropertyNodeItem;
			this.centerList.RefreshContral(propertyNodeItem.DisplayName, this.m_CommandTableInfos);
		}

		private void btnAdd_Click(object sender, RoutedEventArgs e)
		{
			this.rightList.AddNode("自定义1", true);
		}

		private void btnSub_Click(object sender, RoutedEventArgs e)
		{
			this.rightList.DeleteNode(this.leftList, this.centerList, this.m_CommandTableInfos);
		}

		private void btnDown_Click(object sender, RoutedEventArgs e)
		{
			this.rightList.NodeDown(1);
		}

		private void btnUp_Click(object sender, RoutedEventArgs e)
		{
			this.rightList.NodeUp(1);
		}

		private void btnLeft_Click(object sender, MouseButtonEventArgs e)
		{
			this.rightList.DeleteNode(this.leftList, this.centerList, this.m_CommandTableInfos);
		}

		private void btnRight_Click(object sender, MouseButtonEventArgs e)
		{
			try
			{
				TreeViewItem treeViewItem = this.centerList.treeView.SelectedItem as TreeViewItem;
				TreeViewItem treeViewItem2 = treeViewItem.Parent as TreeViewItem;
				if (treeViewItem != null)
				{
					CommandInfos commandInfos = treeViewItem.Tag as CommandInfos;
					if (commandInfos != null && this.rightList.AddChildNode(treeViewItem.Header.ToString(), commandInfos, null))
					{
						if (treeViewItem2 == null)
						{
							this.centerList.treeView.Items.Remove(treeViewItem);
						}
						else
						{
							treeViewItem2.Items.Remove(treeViewItem);
						}
						commandInfos.CmdShow = false;
					}
				}
			}
			catch
			{
			}
		}

		private void textBox_TextChanged(object sender, TextChangedEventArgs e)
		{
			System.Windows.Forms.TextBox textBox = (System.Windows.Forms.TextBox)sender;
			this.centerList.SearchKeywords(textBox.Text, this.m_CommandTableInfos);
		}

		private void textBox_LostFocus(object sender, RoutedEventArgs e)
		{
			try
			{
				PropertyNodeItem propertyNodeItem = this.leftList.tvProperties.SelectedItem as PropertyNodeItem;
				this.centerList.RefreshContral(propertyNodeItem.DisplayName, this.m_CommandTableInfos);
			}
			catch
			{
			}
		}

		private void textBox_GotFocus(object sender, RoutedEventArgs e)
		{
			System.Windows.Forms.TextBox textBox = (System.Windows.Forms.TextBox)sender;
			this.centerList.SearchKeywords(textBox.Text, this.m_CommandTableInfos);
		}

		private void btnLine_Click(object sender, RoutedEventArgs e)
		{
			this.rightList.AddSplit();
		}

        //[DebuggerNonUserCode]
        //[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
        //public void InitializeComponent()
        //{
        //    if (this._contentLoaded)
        //    {
        //        return;
        //    }
        //    this._contentLoaded = true;
        //    Uri resourceLocator = new Uri("/YJKMenuAssist;component/menumanagecontrols/autodefmenutab.xaml", UriKind.Relative);
        //    Application.LoadComponent(this, resourceLocator);
        //}

        //[DebuggerNonUserCode]
        //[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
        //internal Delegate _CreateDelegate(Type delegateType, string handler)
        //{
        //    return Delegate.CreateDelegate(delegateType, this, handler);
        //}

        //[DebuggerNonUserCode]
        //[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
        //[EditorBrowsable(EditorBrowsableState.Never)]
        //void IComponentConnector.Connect(int connectionId, object target)
        //{
        //    switch (connectionId)
        //    {
        //    case 1:
        //        this.autoDefMenuTabGrid = (AutoDefMenuTab)target;
        //        return;
        //    case 2:
        //        this.label = (Label)target;
        //        return;
        //    case 3:
        //        this.leftList = (LeftList)target;
        //        return;
        //    case 4:
        //        this.centerList = (CenterList)target;
        //        return;
        //    case 5:
        //        this.textBox = (TextBox)target;
        //        this.textBox.GotFocus += this.textBox_GotFocus;
        //        this.textBox.LostFocus += this.textBox_LostFocus;
        //        this.textBox.TextChanged += this.textBox_TextChanged;
        //        return;
        //    case 6:
        //        this.btnRight = (Border)target;
        //        this.btnRight.PreviewMouseLeftButtonUp += this.btnRight_Click;
        //        return;
        //    case 7:
        //        this.imRight = (Image)target;
        //        return;
        //    case 8:
        //        this.btnLeft = (Border)target;
        //        this.btnLeft.PreviewMouseLeftButtonUp += this.btnLeft_Click;
        //        return;
        //    case 9:
        //        this.imLeft = (Image)target;
        //        return;
        //    case 10:
        //        this.rightList = (RightList)target;
        //        return;
        //    case 11:
        //        this.btnAdd = (Button)target;
        //        this.btnAdd.Click += this.btnAdd_Click;
        //        return;
        //    case 12:
        //        this.imAdd = (Image)target;
        //        return;
        //    case 13:
        //        this.btnSub = (Button)target;
        //        this.btnSub.Click += this.btnSub_Click;
        //        return;
        //    case 14:
        //        this.imSub = (Image)target;
        //        return;
        //    case 15:
        //        this.btnUp = (Button)target;
        //        this.btnUp.Click += this.btnUp_Click;
        //        return;
        //    case 16:
        //        this.imUp = (Image)target;
        //        return;
        //    case 17:
        //        this.btnDown = (Button)target;
        //        this.btnDown.Click += this.btnDown_Click;
        //        return;
        //    case 18:
        //        this.imDown = (Image)target;
        //        return;
        //    case 19:
        //        this.btnLine = (Button)target;
        //        this.btnLine.Click += this.btnLine_Click;
        //        return;
        //    case 20:
        //        this.imLine = (Image)target;
        //        return;
        //    default:
        //        this._contentLoaded = true;
        //        return;
        //    }
        //}

		private CommandTableInfos m_CommandTableInfos;

        //internal AutoDefMenuTab autoDefMenuTabGrid;

        //internal Label label;

		internal LeftList leftList;

		internal CenterList centerList;

        //internal System.Windows.Forms.TextBox textBox;

        //internal Border btnRight;

        //internal Image imRight;

        //internal Border btnLeft;

        //internal Image imLeft;

		internal RightList rightList;

        //internal Button btnAdd;

        //internal Image imAdd;

        //internal Button btnSub;

        //internal Image imSub;

        //internal Button btnUp;

        //internal Image imUp;

        //internal Button btnDown;

        //internal Image imDown;

        //internal Button btnLine;

        //internal Image imLine;

        //private bool _contentLoaded;
	}
}
